package com.mdlib.helper.ui.adapter;

import android.graphics.drawable.Drawable;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.ljlib.core.util.common.TimeUtils;
import com.ljlib.help.R;
import com.mdlib.helper.model.entity.OrderEntity;

import java.util.List;

/**
 * 作者：HQY on 16/11/22 17:28
 * 邮箱：hqy_xz@126.com
 */

public class SendMyOrderAdapter extends BaseQuickAdapter<OrderEntity> {

    public SendMyOrderAdapter(List<OrderEntity> data) {
        super(R.layout.item_send_my_order, data);
    }

    @Override
    protected void convert(BaseViewHolder baseViewHolder, OrderEntity order) {
        baseViewHolder.setText(R.id.tv_service_money, "￥" + order.getServiceMoney())
                .setText(R.id.tv_goods_money, "￥" + order.getSpendMoney())
                .setText(R.id.tv_my_order_name, order.getRemark())
                .setText(R.id.tv_order_post_addr, order.getGetAddr());


        if (order.getHopeTime() == 0) {
            baseViewHolder.setText(R.id.tv_my_order_success_time, mContext.getResources().getString(R.string.generic_order_success_time));
        } else {
            baseViewHolder.setText(R.id.tv_my_order_success_time, TimeUtils.milliseconds2String(Long.valueOf(order.getHopeTime()) * 1000, TimeUtils.SUCCESS_MONTH));
        }
        TextView mTvSendOrderTips = baseViewHolder.getView(R.id.tv_my_order_type);
        ImageView mIvSendOrderTips = baseViewHolder.getView(R.id.tv_my_order_cancel);
        ImageView mIvOrderReceived = baseViewHolder.getView(R.id.iv_order_received);

        if (order.getOrderStatus() == 0) {
            mTvSendOrderTips.setText(mContext.getResources().getString(R.string.generic_order_type_zore));
            mIvSendOrderTips.setVisibility(View.GONE);
            mIvOrderReceived.setVisibility(View.GONE);
            mTvSendOrderTips.setVisibility(View.VISIBLE);
        } else if (order.getOrderStatus() == 1) {
            mTvSendOrderTips.setText(mContext.getResources().getString(R.string.generic_order_type_one));
            mIvSendOrderTips.setVisibility(View.GONE);
            mIvOrderReceived.setVisibility(View.GONE);
            mTvSendOrderTips.setVisibility(View.VISIBLE);
        } else if (order.getOrderStatus() == 2) {
            mTvSendOrderTips.setText(mContext.getResources().getString(R.string.generic_order_type_two));
            mIvSendOrderTips.setVisibility(View.GONE);
            mTvSendOrderTips.setVisibility(View.VISIBLE);
            mIvOrderReceived.setVisibility(View.VISIBLE);
            Glide.with(mContext)
                    .load(R.drawable.iv_order_pay_received)
                    .into(mIvOrderReceived);
        } else if (order.getOrderStatus() == 5) {
            mTvSendOrderTips.setText(mContext.getResources().getString(R.string.generic_order_type_five_tip));
            mIvSendOrderTips.setVisibility(View.GONE);
            mTvSendOrderTips.setVisibility(View.VISIBLE);
            mIvOrderReceived.setVisibility(View.VISIBLE);
            Glide.with(mContext)
                    .load(R.mipmap.iv_my_order_success)
                    .into(mIvOrderReceived);
        } else if (order.getOrderStatus() == 6) {
            mTvSendOrderTips.setText(mContext.getResources().getString(R.string.generic_order_type_six));
            mIvSendOrderTips.setVisibility(View.GONE);
            mTvSendOrderTips.setVisibility(View.VISIBLE);
            mIvOrderReceived.setVisibility(View.VISIBLE);
            Glide.with(mContext)
                    .load(R.mipmap.iv_my_order_success)
                    .into(mIvOrderReceived);
        } else if (order.getOrderStatus() == 7) {
            mTvSendOrderTips.setText(mContext.getResources().getString(R.string.generic_order_type_seven));
            mIvSendOrderTips.setVisibility(View.GONE);
            mTvSendOrderTips.setVisibility(View.VISIBLE);
            mIvOrderReceived.setVisibility(View.VISIBLE);
            Glide.with(mContext)
                    .load(R.mipmap.iv_my_order_success)
                    .into(mIvOrderReceived);
        } else if (order.getOrderStatus() == 8) {
            mTvSendOrderTips.setText(mContext.getResources().getString(R.string.generic_order_type_eight));
            mIvSendOrderTips.setVisibility(View.VISIBLE);
            mTvSendOrderTips.setVisibility(View.GONE);
            mIvOrderReceived.setVisibility(View.GONE);
        } else if (order.getOrderStatus() == 9) {
            mTvSendOrderTips.setText(mContext.getResources().getString(R.string.generic_order_type_night));
            mIvSendOrderTips.setVisibility(View.GONE);
            mTvSendOrderTips.setVisibility(View.VISIBLE);
            mIvOrderReceived.setVisibility(View.GONE);
        }

        TextView orderTake = baseViewHolder.getView(R.id.tv_my_order_take);
        TextView orderType = baseViewHolder.getView(R.id.tv_order_type);
        if (order.getBusType() == 1) {
            Drawable agency = mContext.getResources().getDrawable(R.drawable.iv_details_agecy);
            agency.setBounds(0, 0, agency.getMinimumWidth(), agency.getMinimumHeight());
            orderType.setCompoundDrawables(null, agency, null, null);
            orderType.setText(mContext.getResources().getString(R.string.send_home_agency));


            Drawable agencys = mContext.getResources().getDrawable(R.drawable.vicinity_order_class);
            agencys.setBounds(0, 0, agencys.getMinimumWidth(), agencys.getMinimumHeight());
            orderTake.setCompoundDrawables(agencys, null, null, null);
            orderTake.setText(order.getHandleType());
            orderTake.setVisibility(View.VISIBLE);

            if (order.getOrderStatus() == 3) {
                if (order.getOfflinePayGoods().equals("true")) {
                    mTvSendOrderTips.setText(mContext.getResources().getString(R.string.details_order_offline_pay));
                } else {
                    mTvSendOrderTips.setText(mContext.getResources().getString(R.string.generic_agency_order_type_three));
                }
                mIvSendOrderTips.setVisibility(View.GONE);
                mTvSendOrderTips.setVisibility(View.VISIBLE);
                mIvOrderReceived.setVisibility(View.VISIBLE);
                Glide.with(mContext)
                        .load(R.drawable.iv_order_pay_received)
                        .into(mIvOrderReceived);
            } else if (order.getOrderStatus() == 4) {
                mTvSendOrderTips.setText(mContext.getResources().getString(R.string.generic_agency_order_type_four));
                mIvSendOrderTips.setVisibility(View.GONE);
                mTvSendOrderTips.setVisibility(View.VISIBLE);
                mIvOrderReceived.setVisibility(View.VISIBLE);
                Glide.with(mContext)
                        .load(R.drawable.iv_order_pay_received)
                        .into(mIvOrderReceived);
            }

        } else if (order.getBusType() == 2) {
            orderTake.setVisibility(View.GONE);
            Drawable agency = mContext.getResources().getDrawable(R.drawable.iv_details_minnetonka);
            agency.setBounds(0, 0, agency.getMinimumWidth(), agency.getMinimumHeight());
            orderType.setCompoundDrawables(null, agency, null, null);
            orderType.setText(mContext.getResources().getString(R.string.send_home_minnetonka));
            if (order.getOrderStatus() == 3) {
                if (order.getOfflinePayGoods().equals("true")) {
                    mTvSendOrderTips.setText(mContext.getResources().getString(R.string.details_order_offline_pay));
                } else {
                    mTvSendOrderTips.setText(mContext.getResources().getString(R.string.generic_minn_order_type_three));
                }
                mIvSendOrderTips.setVisibility(View.GONE);
                mTvSendOrderTips.setVisibility(View.VISIBLE);
                mIvOrderReceived.setVisibility(View.VISIBLE);
                Glide.with(mContext)
                        .load(R.drawable.iv_order_pay_received)
                        .into(mIvOrderReceived);
            } else if (order.getOrderStatus() == 4) {
                mTvSendOrderTips.setText(mContext.getResources().getString(R.string.generic_agency_order_type_four));
                mIvSendOrderTips.setVisibility(View.GONE);
                mTvSendOrderTips.setVisibility(View.VISIBLE);
                mIvOrderReceived.setVisibility(View.VISIBLE);
                Glide.with(mContext)
                        .load(R.drawable.iv_order_pay_received)
                        .into(mIvOrderReceived);
            }
        } else if (order.getBusType() == 3) {
            if (order.getOrderStatus() == 3) {
                if (order.getOfflinePayGoods().equals("true")) {
                    mTvSendOrderTips.setText(mContext.getResources().getString(R.string.details_order_offline_pay));
                } else {
                    mTvSendOrderTips.setText(mContext.getResources().getString(R.string.generic_agency_order_type_three));
                }
                mIvSendOrderTips.setVisibility(View.GONE);
                mTvSendOrderTips.setVisibility(View.VISIBLE);
                mIvOrderReceived.setVisibility(View.VISIBLE);
                Glide.with(mContext)
                        .load(R.drawable.iv_order_pay_received)
                        .into(mIvOrderReceived);
            } else if (order.getOrderStatus() == 4) {
                mTvSendOrderTips.setText(mContext.getResources().getString(R.string.generic_agency_order_type_four));
                mIvSendOrderTips.setVisibility(View.GONE);
                mTvSendOrderTips.setVisibility(View.VISIBLE);
                mIvOrderReceived.setVisibility(View.VISIBLE);
                Glide.with(mContext)
                        .load(R.drawable.iv_order_pay_received)
                        .into(mIvOrderReceived);
            }
            Drawable take = mContext.getResources().getDrawable(R.drawable.iv_details_take);
            take.setBounds(0, 0, take.getMinimumWidth(), take.getMinimumHeight());
            orderType.setCompoundDrawables(null, take, null, null);
            orderType.setText(mContext.getResources().getString(R.string.send_home_take));

            Drawable takes = mContext.getResources().getDrawable(R.mipmap.vicinity_order_take);
            takes.setBounds(0, 0, takes.getMinimumWidth(), takes.getMinimumHeight());
            orderTake.setCompoundDrawables(takes, null, null, null);
            orderTake.setText(order.getPostAddr());
            orderTake.setVisibility(View.VISIBLE);
        } else if (order.getBusType() == 4) {

        }
    }
}
